{% extends "base.html" %}

{% block title %}文件列表 - cr文档管理系统{% endblock %}

{% block content %}
<div class="container mx-auto px-4 py-8">
    <!-- 顶部操作栏 -->
    <div class="bg-white dark:bg-gray-800 rounded-lg shadow-md p-4 mb-8">
        <div class="flex justify-between items-center">
            <div class="flex items-center space-x-6">
                <h1 class="text-xl font-bold text-gray-800 dark:text-white">文件管理</h1>
                <!-- 运行时间显示 -->
                <div class="flex items-center px-4 py-2 bg-indigo-50 dark:bg-indigo-900 rounded-lg border border-indigo-200 dark:border-indigo-700">
                    <div class="flex items-center">
                        <div class="w-2 h-2 bg-green-500 rounded-full animate-pulse mr-2"></div>
                        <span class="system-uptime text-indigo-700 dark:text-indigo-300 font-medium">运行时间: 计算中...</span>
                    </div>
                </div>
            </div>
            <div class="flex items-center space-x-4">
                <div class="flex items-center text-sm text-gray-600 dark:text-gray-300">
                    <i class="fas fa-user mr-1"></i>
                    <span>管理员</span>
                </div>
                <a href="#" onclick="showSystemSettings()" class="text-gray-600 dark:text-gray-300 hover:text-primary">
                    <i class="fas fa-cog"></i>
                    <span class="ml-1">系统设置</span>
                </a>
                <a href="{{ url_for('auth.logout') }}" class="flex items-center text-red-600 hover:text-red-700">
                    <i class="fas fa-sign-out-alt mr-1"></i>
                    <span>退出登录</span>
                </a>
            </div>
        </div>
    </div>


    <!-- 文件上传区域 -->
    <div class="bg-white rounded-lg shadow-md p-6 mb-8">
        <h2 class="text-xl font-semibold text-gray-800 mb-4">上传文件</h2>
        <div class="drop-zone p-8 bg-gray-50 border-2 border-dashed border-gray-300 rounded-lg">
            <form id="uploadForm" action="{{ url_for('upload.upload_file') }}" method="post" enctype="multipart/form-data" class="space-y-4">
                <div class="flex items-center justify-center">
                    <label for="file" class="cursor-pointer text-center">
                        <svg class="mx-auto h-12 w-12 text-gray-400" stroke="currentColor" fill="none" viewBox="0 0 48 48">
                            <path d="M28 8H12a4 4 0 00-4 4v20m32-12v8m0 0v8a4 4 0 01-4 4H12a4 4 0 01-4-4v-4m32-4l-3.172-3.172a4 4 0 00-5.656 0L28 28M8 32l9.172-9.172a4 4 0 015.656 0L28 28m0 0l4 4m4-24h8m-4-4v8m-12 4h.02" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
                        </svg>
                        <p class="mt-2 text-sm text-gray-600">
                            点击或拖拽文件到此处上传
                        </p>
                        <p class="mt-1 text-xs text-gray-500">
                            支持的文件类型: TXT, PDF, DOC, DOCX, XLS, XLSX, PPT, PPTX<br>
                            单个文件最大支持: 1GB
                        </p>
                    </label>
                    <input id="file" name="file" type="file" class="hidden" accept=".txt,.pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx">
                </div>
            </form>
        </div>
        <!-- 上传进度条 -->
        <div class="mt-4">
            <div class="flex items-center justify-between mb-2">
                <span class="text-sm text-gray-600" id="upload-status">准备上传...</span>
                <span class="text-sm text-gray-600" id="upload-percentage">0%</span>
            </div>
            <div class="progress bg-gray-200 rounded-full overflow-hidden">
                <div class="progress-bar w-0 h-2 bg-indigo-600 transition-all duration-300"></div>
            </div>
            <div class="flex justify-between mt-2 text-xs text-gray-500">
                <span id="upload-speed">上传速度: 0 KB/s</span>
                <span id="upload-remaining">剩余时间: 计算中...</span>
            </div>
        </div>
    </div>

    <!-- 文件列表 -->
    <div class="bg-white rounded-lg shadow-md overflow-hidden">
        <div class="px-6 py-4 border-b border-gray-200">
            <div class="flex justify-between items-center">
                <h2 class="text-xl font-semibold text-gray-800">文件列表</h2>
                <div class="relative">
                    <input type="text" id="file-search" placeholder="搜索文件..." 
                        class="pl-10 pr-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">
                    <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                        <svg class="h-5 w-5 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"/>
                        </svg>
                    </div>
                </div>
            </div>
        </div>
        <div class="divide-y divide-gray-200">
            {% for file in files %}
            <div class="file-item p-4 hover:bg-gray-50 transition-colors duration-150">
                <div class="flex items-center justify-between">
                    <div class="flex items-center space-x-4">
                        <!-- 文件图标 -->
                        <div class="file-icon flex-shrink-0">
                            {% if file.filename.lower().endswith(('.doc', '.docx')) or file.file_type == 'word' %}
                            <svg class="w-8 h-8 text-blue-600" fill="currentColor" viewBox="0 0 20 20">
                                <path d="M4 4a2 2 0 012-2h8a2 2 0 012 2v12a2 2 0 01-2 2H6a2 2 0 01-2-2V4z"/>
                            </svg>
                            {% elif file.filename.lower().endswith(('.xls', '.xlsx')) or file.file_type == 'excel' %}
                            <svg class="w-8 h-8 text-green-600" fill="currentColor" viewBox="0 0 20 20">
                                <path d="M4 4a2 2 0 012-2h8a2 2 0 012 2v12a2 2 0 01-2 2H6a2 2 0 01-2-2V4z"/>
                            </svg>
                            {% elif file.filename.lower().endswith(('.ppt', '.pptx')) or file.file_type == 'powerpoint' %}
                            <svg class="w-8 h-8 text-orange-600" fill="currentColor" viewBox="0 0 20 20">
                                <path d="M4 4a2 2 0 012-2h8a2 2 0 012 2v12a2 2 0 01-2 2H6a2 2 0 01-2-2V4z"/>
                            </svg>
                            {% elif file.filename.lower().endswith('.pdf') or file.file_type == 'pdf' %}
                            <svg class="w-8 h-8 text-red-600" fill="currentColor" viewBox="0 0 20 20">
                                <path d="M4 4a2 2 0 012-2h8a2 2 0 012 2v12a2 2 0 01-2 2H6a2 2 0 01-2-2V4z"/>
                            </svg>
                            {% elif file.filename.lower().endswith(('.jpg', '.jpeg', '.png', '.gif')) or file.file_type == 'image' %}
                            <svg class="w-8 h-8 text-purple-600" fill="currentColor" viewBox="0 0 20 20">
                                <path d="M4 4a2 2 0 012-2h8a2 2 0 012 2v12a2 2 0 01-2 2H6a2 2 0 01-2-2V4z"/>
                            </svg>
                            {% else %}
                            <svg class="w-8 h-8 text-gray-400" fill="currentColor" viewBox="0 0 20 20">
                                <path d="M4 4a2 2 0 012-2h8a2 2 0 012 2v12a2 2 0 01-2 2H6a2 2 0 01-2-2V4z"/>
                            </svg>
                            {% endif %}
                        </div>
                        
                        <!-- 下载按钮 -->
                        <a href="{{ url_for('download.download_file', filename=file.filename) }}" class="text-indigo-600 hover:text-indigo-900 flex-shrink-0">
                            <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"/>
                            </svg>
                        </a>
                        
                        <!-- 文件信息 -->
                        <div class="flex-1 min-w-0">
                            <p class="text-sm font-medium text-gray-900 truncate">
                                {{ file.original_name if file.original_name else file.filename }}
                            </p>
                            <div class="flex items-center space-x-4 mt-1">
                                <p class="text-xs text-gray-500">
                                    <i class="fas fa-clock mr-1"></i>
                                    {{ file.upload_time }}
                                </p>
                                <p class="text-xs text-gray-500">
                                    <i class="fas fa-network-wired mr-1"></i>
                                    {{ file.uploader_ip }}
                                </p>
                                <p class="text-xs text-gray-500">
                                    <i class="fas fa-map-marker-alt mr-1"></i>
                                    {{ file.uploader_location }}
                                </p>
                                <p class="text-xs text-gray-500">
                                    <i class="fas fa-hdd mr-1"></i>
                                    {{ (file.size / 1024)|round(1) }} KB
                                </p>
                            </div>
                        </div>
                    </div>
                    <!-- 操作按钮 -->
                    <div class="flex items-center space-x-2">
                        {% if file.filename.endswith(('.jpg', '.jpeg', '.png', '.gif', '.pdf')) %}
                        <button class="text-gray-600 hover:text-gray-900" data-preview="{{ url_for('download.download_file', filename=file.filename) }}">
                            <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/>
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"/>
                            </svg>
                        </button>
                        {% endif %}
                    </div>
                </div>
            </div>
            {% else %}
            <div class="p-4 text-center text-gray-500">
                暂无文件
            </div>
            {% endfor %}
        </div>
    </div>
</div>

<!-- 系统信息模块 -->
<div class="container mx-auto px-4 py-8">
    <div class="bg-white dark:bg-gray-800 rounded-lg shadow-md overflow-hidden">
        <div class="px-6 py-4 border-b border-gray-200 dark:border-gray-700">
            <div class="flex justify-between items-center">
                <h2 class="text-xl font-semibold text-gray-800 dark:text-white flex items-center">
                    <i class="fas fa-server mr-2 text-indigo-600"></i>
                    系统信息
                </h2>
                <button id="refresh-system-info" class="p-2 rounded-full hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-600 dark:text-gray-300" title="刷新系统信息">
                    <i class="fas fa-sync-alt"></i>
                </button>
            </div>
        </div>
        <div class="p-6">
            <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
                <!-- 系统状态 -->
                <div class="bg-gradient-to-br from-indigo-50 to-blue-50 dark:from-gray-700 dark:to-gray-800 rounded-lg p-4 shadow">
                    <div class="flex items-center justify-between mb-3">
                        <h3 class="text-lg font-medium text-gray-800 dark:text-white">系统状态</h3>
                        <div class="flex items-center">
                            <span class="status-indicator w-2 h-2 rounded-full bg-green-500"></span>
                            <span class="text-sm text-green-600 dark:text-green-400 ml-1">正常运行</span>
                        </div>
                    </div>
                    <div class="flex items-center mt-2">
                        <i class="fas fa-clock text-gray-500 mr-2"></i>
                        <span class="text-sm text-gray-600 dark:text-gray-300 system-uptime">运行时间: 计算中...</span>
                    </div>
                    <div class="flex items-center mt-2">
                        <i class="fas fa-thermometer-half text-gray-500 mr-2"></i>
                        <span class="text-sm text-gray-600 dark:text-gray-300">系统负载: <span id="system-load">0.00</span></span>
                    </div>
                    <div class="flex items-center mt-2">
                        <i class="fas fa-server text-gray-500 mr-2"></i>
                        <span class="text-sm text-gray-600 dark:text-gray-300" id="system-platform">获取中...</span>
                    </div>
                </div>
                
                <!-- 存储信息 -->
                <div class="bg-gradient-to-br from-purple-50 to-indigo-50 dark:from-gray-700 dark:to-gray-800 rounded-lg p-4 shadow">
                    <div class="flex items-center justify-between mb-3">
                        <h3 class="text-lg font-medium text-gray-800 dark:text-white">存储信息</h3>
                        <span class="text-sm text-gray-500 dark:text-gray-400">总计: <span id="total-storage">计算中...</span></span>
                    </div>
                    <div class="w-full bg-gray-200 dark:bg-gray-600 rounded-full h-2.5 mb-2">
                        <div class="bg-indigo-600 h-2.5 rounded-full" style="width: 0%"></div>
                    </div>
                    <div class="flex justify-between items-center text-xs text-gray-600 dark:text-gray-300">
                        <span>已用: <span id="used-storage">计算中...</span></span>
                        <span>可用: <span id="free-storage">计算中...</span></span>
                    </div>
                </div>
                
                <!-- 文件统计 -->
                <div class="bg-gradient-to-br from-blue-50 to-cyan-50 dark:from-gray-700 dark:to-gray-800 rounded-lg p-4 shadow">
                    <div class="flex items-center justify-between mb-3">
                        <h3 class="text-lg font-medium text-gray-800 dark:text-white">文件统计</h3>
                        <i class="fas fa-file-alt text-gray-500"></i>
                    </div>
                    <div class="grid grid-cols-2 gap-2 text-center">
                        <div class="bg-white dark:bg-gray-800 rounded p-2 shadow-sm">
                            <p class="text-lg font-semibold text-indigo-600 dark:text-indigo-400" id="total-files">--</p>
                            <p class="text-xs text-gray-500 dark:text-gray-400">总文件数</p>
                        </div>
                        <div class="bg-white dark:bg-gray-800 rounded p-2 shadow-sm">
                            <p class="text-lg font-semibold text-indigo-600 dark:text-indigo-400" id="total-download">--</p>
                            <p class="text-xs text-gray-500 dark:text-gray-400">总下载数</p>
                        </div>
                        <div class="bg-white dark:bg-gray-800 rounded p-2 shadow-sm">
                            <p class="text-lg font-semibold text-indigo-600 dark:text-indigo-400" id="upload-today">--</p>
                            <p class="text-xs text-gray-500 dark:text-gray-400">今日上传</p>
                        </div>
                        <div class="bg-white dark:bg-gray-800 rounded p-2 shadow-sm">
                            <p class="text-lg font-semibold text-indigo-600 dark:text-indigo-400" id="download-today">--</p>
                            <p class="text-xs text-gray-500 dark:text-gray-400">今日下载</p>
                        </div>
                    </div>
                </div>
                
                <!-- 系统事件 -->
                <div class="bg-gradient-to-br from-green-50 to-teal-50 dark:from-gray-700 dark:to-gray-800 rounded-lg p-4 shadow">
                    <div class="flex items-center justify-between mb-2">
                        <h3 class="text-lg font-medium text-gray-800 dark:text-white">最近事件</h3>
                        <i class="fas fa-history text-gray-500"></i>
                    </div>
                    <div class="space-y-1 overflow-y-auto max-h-[120px]" id="system-events">
                        <div class="flex items-start space-x-2 text-xs">
                            <span class="text-gray-500 dark:text-gray-400 whitespace-nowrap">加载中...</span>
                            <span class="text-gray-700 dark:text-gray-300">正在获取系统事件</span>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 系统资源图表 -->
            <div class="mt-6 grid grid-cols-1 md:grid-cols-2 gap-6">
                <div class="bg-white dark:bg-gray-800 rounded-lg p-4 shadow">
                    <h3 class="text-lg font-medium text-gray-800 dark:text-white mb-4">CPU & 内存使用率</h3>
                    <div id="resource-chart" class="w-full h-64"></div>
                </div>
                <div class="bg-white dark:bg-gray-800 rounded-lg p-4 shadow">
                    <h3 class="text-lg font-medium text-gray-800 dark:text-white mb-4">文件类型分布</h3>
                    <div id="file-type-chart" class="w-full h-64"></div>
                </div>
            </div>
            
            <!-- 更新时间指示 -->
            <div class="mt-4 text-right text-xs text-gray-500 dark:text-gray-400">
                <span>最后更新: <span id="last-update-time">-</span></span>
                <span class="ml-2">(每 <span id="update-interval">30</span> 秒自动更新)</span>
            </div>
        </div>
    </div>
</div>

<!-- 主题切换按钮 -->
<div class="fixed bottom-4 right-4">
    <button id="theme-toggle" class="p-2 rounded-full bg-white shadow-lg hover:bg-gray-100 focus:outline-none">
        <svg class="w-6 h-6 text-gray-800" fill="none" stroke="currentColor" viewBox="0 0 24 24">
            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z"/>
        </svg>
    </button>
</div>

<!-- 底部文档链接区域 -->
<div class="mt-12 bg-gradient-to-r from-indigo-500 via-purple-500 to-pink-500 text-white">
    <div class="container mx-auto px-4 py-12">
        <div class="grid grid-cols-1 md:grid-cols-3 gap-8">
            <!-- 项目介绍 -->
            <div class="space-y-4">
                <h3 class="text-xl font-bold">关于项目</h3>
                <p class="text-gray-100">cr文档管理系统是一个现代化的文件管理平台，提供安全、高效的文件存储和管理服务。支持多种文件格式，实时同步，快速搜索等功能。</p>
            </div>
            <!-- 快速链接 -->
            <div class="space-y-4">
                <h3 class="text-xl font-bold">快速链接</h3>
                <ul class="space-y-2">
                    <li>
                        <a href="https://gitee.com/CRGOGOGO/upload.git" target="_blank" class="flex items-center hover:text-gray-200">
                            <i class="fab fa-git-alt mr-2"></i>
                            <span>项目源码</span>
                        </a>
                    </li>
                    <li>
                        <a href="#" class="flex items-center hover:text-gray-200">
                            <i class="fas fa-book mr-2"></i>
                            <span>使用文档</span>
                        </a>
                    </li>
                    <li>
                        <a href="#" class="flex items-center hover:text-gray-200">
                            <i class="fas fa-question-circle mr-2"></i>
                            <span>常见问题</span>
                        </a>
                    </li>
                </ul>
            </div>
            <!-- 技术支持 -->
            <div class="space-y-4">
                <h3 class="text-xl font-bold">技术支持</h3>
                <div class="space-y-2">
                    <p class="flex items-center">
                        <i class="fas fa-envelope mr-2"></i>
                        <span>联系邮箱：support@example.com</span>
                    </p>
                    <p class="flex items-center">
                        <i class="fas fa-clock mr-2"></i>
                        <span>工作时间：周一至周五 9:00-18:00</span>
                    </p>
                    <p class="text-sm mt-4">
                        版本：v1.0.0 | &copy; 2024 cr文档管理系统
                    </p>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block scripts %}
<script src="{{ url_for('static', filename='js/main.js') }}"></script>
{% endblock %} 